#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// 1. 从标准输入读取如何优化，更方便
// 2. 标准输出如何优化

int  main() {
    // string input;
    // cin >> input;
    // parse input 
    // char ch;
    // while (cin.get(ch))
    cout << cin.flags() << endl;

    string input;
    int id;
    vector<pair<int, int>> vlan_resourse;
    cin >> input;
    cin >> id;
    int vlan_begin = 0;
    int i;
    // int vlan_end = 0;
    for (i = 0; i < input.size(); ++i) {
        if (input[i] == ',') {
            // vlan_end =  i - 1;
            string vlan_string = input.substr(vlan_begin, i-vlan_begin);
            // check '-'
            size_t seq_idx;
            if ((seq_idx = vlan_string.find('-')) != string::npos) {
                vlan_resourse.push_back(pair<int, int>(stoi(vlan_string.substr(0, seq_idx)), stoi(vlan_string.substr(seq_idx+1, vlan_string.size()-seq_idx))));
            } else {
                vlan_resourse.push_back(pair<int, int>(stoi(vlan_string), stoi(vlan_string)));
            }
            vlan_begin = i+1;
        }
    }
    // vlan_end =  i - 1;
    string vlan_string = input.substr(vlan_begin, i-vlan_begin);
    // check '-'
    size_t seq_idx;
    if ((seq_idx = vlan_string.find('-')) != string::npos) {
        vlan_resourse.push_back(pair<int, int>(stoi(vlan_string.substr(0, seq_idx)), stoi(vlan_string.substr(seq_idx+1, vlan_string.size()-seq_idx))));
    } else {
        vlan_resourse.push_back(pair<int, int>(stoi(vlan_string), stoi(vlan_string)));
    }
    

    // sort vlan resource
    sort(vlan_resourse.begin(), vlan_resourse.end());    

    // delete used vlan
    int begin = 0;
    int end = vlan_resourse.size()-1;
    int mid = (begin+end)/2;
    // int midd = vlan_resourse.size() / 2;
    while (begin <= end) {
        if (vlan_resourse[mid].first == vlan_resourse[mid].second && (vlan_resourse[mid].first == id)) {
            vlan_resourse.erase(vlan_resourse.begin()+mid);
            break;
        } else if (vlan_resourse[mid].first == id) {
            vlan_resourse[mid].first = id + 1;
            break;
        } else if (vlan_resourse[mid].second == id) {
            vlan_resourse[mid].second = id - 1;
            break;
        } else if (vlan_resourse[mid].first < id && (vlan_resourse[mid].second > id)) {
            // To Do
            vlan_resourse.insert(vlan_resourse.begin()+mid+1, pair<int, int>(id+1, vlan_resourse[mid].second));
            vlan_resourse[mid].second = id-1;
            break;
        } else if (vlan_resourse[mid].first > id) {
            end = mid-1;
        } else if (vlan_resourse[mid].second < id) {
            begin = mid+1;
        }
        mid = (begin + end) / 2;
    }
    // output
    // To Do
    string output;
    for(auto pair:vlan_resourse) {
        if (pair.first == pair.second) {
            output  = output + to_string(pair.first);
            output.push_back(',');
        } else {
            output = output + to_string(pair.first);
            output.push_back('-');
            output = output + to_string(pair.second);
            output.push_back(',');
        }
    }
    output.pop_back();
    cout << output;
}